import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/home/index.dart';
import 'package:flutter_enjoy_plus/pages/mine/index.dart';

class TabsPage extends StatefulWidget {
  const TabsPage({super.key});

  @override
  _TabsPageState createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  List bottomTabs = [
    {
      'label': '首页',
      'icon': 'assets/tabs/home_default.png',
      'activeIcon': 'assets/tabs/home_active.png'
    },
    {
      'label': '我的',
      'icon': 'assets/tabs/my_default.png',
      'activeIcon': 'assets/tabs/my_active.png'
    }
  ];
  // 当前选中的索引
  int _currentIndex = 0;

  // 获取底部导航栏
  getBottomTabs() {
    List<BottomNavigationBarItem> list = [];

    for (var item in bottomTabs) {
      list.add(
        BottomNavigationBarItem(
          icon: Image.asset(
            item['icon'],
            width: 30,
            height: 30,
          ),
          activeIcon: Image.asset(
            item['activeIcon'],
            width: 30,
            height: 30,
          ),
          label: item['label'],
        ),
      );
    }

    return list;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: IndexedStack(
          index: _currentIndex,
          children: const [HomePage(), MinePage()],
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        elevation: null,
        enableFeedback: false,
        selectedItemColor: const Color.fromRGBO(62, 146, 175, 1),
        onTap: (value) {
          setState(() {
            _currentIndex = value;
          });
        },
        items: getBottomTabs(),
      ),
    );
  }
}
